import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public class demo1 {
    public static void main(String[] args) throws Exception{
        Path p1 = Paths.get("d:/123.txt");
        if(Files.exists(p1))
            Files.delete(p1);

        Files.createFile(p1);

        Path p2 = Paths.get("d:/456.txt");
        Files.copy(p1,p2, StandardCopyOption.REPLACE_EXISTING);

        Path p3 = Paths.get("d:/789.txt");
        Files.move(p1,p3, StandardCopyOption.REPLACE_EXISTING);
    }


    public static void main3(String[] args) {
        walk(new File("d:/source"),0);
    }

    public static void walk(File f, int level){
        for (int i = 0; i < level; i++) {
            System.out.print("--");
        }
        System.out.println(f.getAbsolutePath());

        if(f.isDirectory()){
            for (File x:
                 f.listFiles()) {
                walk(x,level+1);
            }
        }
    }


    public static void main2(String[] args) {
//        File f = new File("d:/zzz/yyy/xxx");
//        f.mkdirs();

        File f2 = new File("d:/");
        File[] fs = f2.listFiles();
        for (File x:
                fs) {
            System.out.print(x.getAbsolutePath() + "-");
            System.out.print(x.isDirectory() + "-");
            System.out.println(x.length());
        }
    }


    public static void main1(String[] args) {
        File f = new File("d:/zzz/yyy/xxx");   //路径指向
        if(f.exists())
            f.delete();

        try {
            f.createNewFile();
        }catch (IOException ex){
            ex.printStackTrace();
        }

        System.out.println(f.getName());
        System.out.println(f.getAbsolutePath());
        System.out.println(f.canWrite());
        System.out.println(f.isDirectory());
        System.out.println(f.length());
    }
}
